package jcu.ict.profaid;

import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.widget.TabHost;

@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
public class MainCourse extends TabActivity {
	private SessionManager session;
	private String i;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main_result);

		session = new SessionManager(getApplicationContext());
		session.checkLogin();
		
		Bundle bundle = this.getIntent().getExtras();
		i = (String) bundle.getCharSequence("setUserId");

		ActionBar actionBar = getActionBar();
		actionBar.setDisplayHomeAsUpEnabled(true);
		ColorDrawable colorDrawable = new ColorDrawable(
				Color.parseColor("#0099CC"));
		actionBar.setBackgroundDrawable(colorDrawable);

		Resources res = getResources();

		Intent iListCourse = new Intent(this, FormListCourse.class);
		Bundle bundles = new Bundle();
		bundles.putCharSequence("setUserId", i);
		iListCourse.putExtras(bundle);
		Intent iAddCourse = new Intent(this, FormAddCourse.class);
		Bundle bundless = new Bundle();
		bundless.putCharSequence("setUserId", i);
		iAddCourse.putExtras(bundle);
		
		TabHost mTabHst = getTabHost();

		mTabHst.addTab(mTabHst
				.newTabSpec("tab_test1")
				.setIndicator("List of Polling", res.getDrawable(R.drawable.one))
				.setContent(iListCourse));
		mTabHst.addTab(mTabHst.newTabSpec("tab_test2")
				.setIndicator("Add Polling", res.getDrawable(R.drawable.two))
				.setContent(iAddCourse));
		mTabHst.setCurrentTab(0);

	}

	@Override
	public void onResume() {
		super.onResume();
	}

	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if ((keyCode == KeyEvent.KEYCODE_BACK)) {
			Intent in = new Intent(MainCourse.this, MainActivity.class);
			Bundle bundle = new Bundle();
			startActivity(in);
		}
		return super.onKeyDown(keyCode, event);
	}

	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			// app icon in action bar clicked; go home
			Intent intent = new Intent(this, MainActivity.class);
			intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			startActivity(intent);
			return true;
		default:
			return super.onOptionsItemSelected(item);
		}
	}
}